<?php
/**
 * Created by PhpStorm.
 * User: zhongyb
 * Date: 2016/6/6
 * Time: 11:12
 */
namespace common\services\common;

use common\entities\ConfigEntity;
use common\repositories\common\MyscrmAsyncoperationRepository;
use common\repositories\common\MyscrmErpauthenticationinfotemplateRepository;
use common\repositories\common\MyscrmErpserviceaddressRepository;
use common\repositories\common\MyscrmErpserviceaddresstemplateRepository;
use common\repositories\common\MyscrmErpserviceRepository;
use common\repositories\common\MyscrmErpservicetemplateRepository;
use common\services\BaseService;
use common\repositories\common\MyscrmErpauthenticationinfoRepository;
use Yii;
use yii\base\Exception;
use \common\support\StringHelper;


class MyscrmErpInterfaceService extends BaseService {

    public $_myscrmErpauthenticationinfoRepository;
    public $_myscrmErpauthenticationinfotemplateRepository;

    public $_myscrmErpserviceaddressRepository;
    public $_myscrmErpserviceaddresstemplateRepository;

    public $_myscrmErpservicetemplateRepository;
    public $_myscrmErpserviceRepository;

    public $_myscrmAsyncoperationRepository;

    public function __construct(MyscrmErpauthenticationinfoRepository $myscrmErpauthenticationinfoRepository,
                                MyscrmErpauthenticationinfotemplateRepository $myscrmErpauthenticationinfotemplateRepository,
                                MyscrmErpserviceaddressRepository $myscrmErpserviceaddressRepository,
                                MyscrmErpserviceaddresstemplateRepository $myscrmErpserviceaddresstemplateRepository,
                                MyscrmErpservicetemplateRepository $myscrmErpservicetemplateRepository,
                                MyscrmErpserviceRepository $myscrmErpserviceRepository,
                                MyscrmAsyncoperationRepository $myscrmAsyncoperationRepository){
        $this->_myscrmErpauthenticationinfoRepository = $myscrmErpauthenticationinfoRepository;
        $this->_myscrmErpauthenticationinfotemplateRepository = $myscrmErpauthenticationinfotemplateRepository;
        $this->_myscrmErpserviceaddressRepository = $myscrmErpserviceaddressRepository;
        $this->_myscrmErpserviceaddresstemplateRepository = $myscrmErpserviceaddresstemplateRepository;
        $this->_myscrmErpservicetemplateRepository = $myscrmErpservicetemplateRepository;
        $this->_myscrmErpserviceRepository = $myscrmErpserviceRepository;
        $this->_myscrmAsyncoperationRepository = $myscrmAsyncoperationRepository;
        parent::__construct();
    }

    /**
     * 记录是否存在
     * @param string $authName
     * @param string $orgId
     * @return bool
     */
    public function isExistsErpauthenticationinfo($authName, $orgId)
    {
        return $this->_myscrmErpauthenticationinfoRepository->isExists($authName, $orgId);
    }

    /**
     * 记录是否存在
     * @param string $authName
     * @param string $orgId
     * @return bool
     */
    public function isExistsErpservice($authName, $orgId)
    {
        return $this->_myscrmErpserviceRepository->isExists($authName, $orgId);
    }

    /**
     * 获取模板
     * @param bool $initOnOrgCreated 是否在创建租户时初始化
     * @return array|\yii\db\ActiveRecord[]
     */
    public function getErpauthenticationinfotemplateList($initOnOrgCreated)
    {
        if($initOnOrgCreated === true){
            $initOnOrgCreated = 1;
        }
        return $this->_myscrmErpauthenticationinfotemplateRepository->getErpauthenticationinfotemplateList($initOnOrgCreated);
    }

    /**
     * 获取模板
     * @param bool $initOnOrgCreated 是否在创建租户时初始化
     * @return array|\yii\db\ActiveRecord[]
     */
    public function getErpserviceaddresstemplateList($initOnOrgCreated)
    {
        if($initOnOrgCreated === true){
            $initOnOrgCreated = 1;
        }
        return $this->_myscrmErpserviceaddresstemplateRepository->getErpserviceaddresstemplateList($initOnOrgCreated);
    }

    /**
     * 获取模板
     * @param bool $initOnOrgCreated 是否在创建租户时初始化
     * @return array|\yii\db\ActiveRecord[]
     */
    public function getErpservicetemplateList($initOnOrgCreated)
    {
        if($initOnOrgCreated === true){
            $initOnOrgCreated = 1;
        }
        return $this->_myscrmErpservicetemplateRepository->getErpservicetemplateList($initOnOrgCreated);
    }

    public function isExistsErpserviceaddress($addressName, $orgId)
    {
        return $this->_myscrmErpserviceaddressRepository->isExists($addressName, $orgId);
    }

}